package com.example.casserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.casserver.entity.User;
import com.example.casserver.mapper.UserMapper;
import com.example.casserver.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    @Override
    public boolean saveUser(User user) {
        // 检查用户名是否已存在
        if (user.getId() == null && userMapper.checkUsernameExists(user.getUsername()) > 0) {
            return false;
        }
        return saveOrUpdate(user);
    }
} 